<template>
  <div>
    <div v-if="Show == 1">
      <div style="margin-bottom: 10px; margin-left: 10px; padding-top: 10px">
        <el-button type="primary" @click="add">新增评估</el-button>
        <el-button @click="goBack">返回</el-button>
      </div>
      <el-table :data="tableData" style="width: 100%; margin-left: 10px">
        <el-table-column label="评估日期" prop="updated_at" />
        <el-table-column label="评估人" prop="user_name" />
        <el-table-column label="操作">
          <template slot-scope="scoped">
            <el-button type="primary" @click="upl(scoped.row)">修改</el-button>
            <el-button
              slot="reference"
              type="danger"
              @click="toVoid(scoped.row)"
            >
              作废
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div v-if="Show == 2">
      <resultList :datas="datas" :dataupl="dataupl" @showMain="showMain" />
    </div>
  </div>
</template>

<script>
  import { feedBack, feedBackDel } from '@/api/edu'

  import resultList from './resultList.vue'

  //
  export default {
    components: { resultList },
    props: {
      datas: {
        type: Object,
        required: true,
      },
    },
    data() {
      return {
        tableData: [],
        Show: 1,
        dataupl: {},
      }
    },
    mounted() {
      this.init()
    },
    methods: {
      init() {
        const data = {
          id: this.datas.id,
        }
        feedBack(data).then((e) => {
          console.log(e)
          this.tableData = e.data
        })
      },

      FamilyChange(e) {
        this.FamilyOptions.forEach((res) => {
          if (res.group_id == e) {
            this.userOptions = res.child
          }
        })
      },
      showMain() {
        this.Show = 1
        this.init()
      },
      goBack() {
        // 返回
        this.$emit('showMain')
      },
      upl(e) {
        console.log(e)
        this.dataupl = e
        this.Show = 2
      },
      toVoid(e) {
        this.$confirm('此操作将永久作废, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
          .then(() => {
            const data = {
              id: e.id,
            }
            feedBackDel(data).then(() => {
              this.init()
            })

            this.$message({
              type: 'success',
              message: '作废成功!',
            })
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消作废',
            })
          })
      },
      add() {
        this.dataupl = {}
        this.Show = 2
      },
    },
  }
</script>

<style></style>
